//transmit support for dynamic_bit_array
//$Id: transmit_dynamic_bit_array.h 522 2010-07-19 18:13:22Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/dynamic_bit_array.h"
#include "src/heo/include/transmit.h"
//__________________________________________________________________________________
//__________________________________________________________________________________
template<class X, class Y, class V>
struct transmit_handler<dynamic_bit_array<X, Y>, V>
{
    static void visit(dynamic_bit_array<X, Y>& m, V& v)
    {
        visit(m, v, meta::int2type<V::transmit_tag>());
    }

    static void visit(dynamic_bit_array<X, Y>& m, V& bcast, meta::int2type<BCAST_TAG>)
    {
        if (bcast.is_Root())
        {
            visit(m, bcast, meta::int2type<SEND_TAG>());
        }
        else
        {
            visit(m, bcast, meta::int2type<RECV_TAG>());
        }
    }

    static void visit(dynamic_bit_array<X, Y>& m, V& send, meta::int2type<SEND_TAG>)
    {
        size_t dim = m.size();
        send << dim;
        if (dim > 0)
            send.visit_Array(m.front_block(), m.block_count(), "", 0);
    }

    static void visit(dynamic_bit_array<X, Y>& m, V& recv, meta::int2type<RECV_TAG>)
    {
        size_t dim = 0;
        recv >> dim;
        m.resize(dim, 0, false);
        if (dim > 0)
            recv.visit_Array(m.front_block(), m.block_count(), "", 0);
    }
};
//__________________________________________________________________________________

//EOF!
